package org.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.lease.mapper.GraphInfoMapper;
import org.lease.model.entity.GraphInfo;
import org.lease.model.enums.ItemType;
import org.lease.model.vo.GraphVo;
import org.lease.service.GraphInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GraphInfoServiceImpl extends ServiceImpl<GraphInfoMapper, GraphInfo> implements GraphInfoService {
    @Override
    public List<GraphVo> listByItemTypeAndItemId(ItemType itemType, Long itemId) {
        LambdaQueryWrapper<GraphInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GraphInfo::getItemType, itemType);
        wrapper.eq(GraphInfo::getItemId, itemId);
        List<GraphInfo> list = list(wrapper);
        List<GraphVo> graphVos = new ArrayList<>();
        list.forEach(graphInfo -> {
            GraphVo graphVo = new GraphVo();
            BeanUtils.copyProperties(graphInfo, graphVo);
            graphVos.add(graphVo);
        });
        return graphVos;
    }
}
